Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace forwardable with explicit delegation for performance #312

Closed
wants to merge 1 commit into from

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Aug 30, 2024

I'm doing performance profiling and was surprised for these to appear at all in the samples. Here are some numbers (3 warmup runs, 20 measured runs, cache used):

# with forwardable in both rubocop + rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile" 
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.169 s ±  0.016 s    [User: 0.976 s, System: 0.190 s]
  Range (min … max):    1.138 s …  1.198 s    20 runs
  
# with forwardable only in rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile" 
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.145 s ±  0.011 s    [User: 0.959 s, System: 0.185 s]
  Range (min … max):    1.131 s …  1.170 s    20 runs

# with forwardable in neither
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile" 
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.136 s ±  0.020 s    [User: 0.950 s, System: 0.183 s]
  Range (min … max):    1.098 s …  1.168 s    20 runs

Overall ~ 3% faster


Full run, also about 3%:

# with forwardable in both rubocop + rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop" 
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.704 s ±  0.018 s    [User: 1.903 s, System: 1.004 s]
  Range (min … max):    1.669 s …  1.742 s    20 runs
  
# with forwardable only in rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop" 
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.677 s ±  0.025 s    [User: 1.847 s, System: 0.988 s]
  Range (min … max):    1.640 s …  1.763 s    20 runs

# with forwardable in neither
$ hyperfine -w 3 -r 20 "bundle exec rubocop" 
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.656 s ±  0.020 s    [User: 1.817 s, System: 0.984 s]
  Range (min … max):    1.630 s …  1.700 s    20 runs

The impact of changing rubocop-ast is not as large as the one in rubocop but its something nontheless. I think this makes sense and the added code is not that complex.

Companion PR for rubocop: rubocop/rubocop#13175


I don't need an immediate release should this get merged. Numbers are not that impressive and its a hard sell for the changelog. I'm fine with waiting for some more substantial change at a later time.

I'm doing performance profiling and was surprised for these to appear
at all in the flamegraph. Here are some numbers:

```
# with forwardable in both rubocop + rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile"
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.169 s ±  0.016 s    [User: 0.976 s, System: 0.190 s]
  Range (min … max):    1.138 s …  1.198 s    20 runs

# with forwardable only in rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile"
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.145 s ±  0.011 s    [User: 0.959 s, System: 0.185 s]
  Range (min … max):    1.131 s …  1.170 s    20 runs

# with forwardable in neither
$ hyperfine -w 3 -r 20 "bundle exec rubocop Rakefile"
Benchmark 1: bundle exec rubocop Rakefile
  Time (mean ± σ):      1.136 s ±  0.020 s    [User: 0.950 s, System: 0.183 s]
  Range (min … max):    1.098 s …  1.168 s    20 runs
```

Overall ~ 3% faster

-------

Full run, also about 3%:

```
# with forwardable in both rubocop + rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop"
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.704 s ±  0.018 s    [User: 1.903 s, System: 1.004 s]
  Range (min … max):    1.669 s …  1.742 s    20 runs

# with forwardable only in rubocop-ast
$ hyperfine -w 3 -r 20 "bundle exec rubocop"
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.677 s ±  0.025 s    [User: 1.847 s, System: 0.988 s]
  Range (min … max):    1.640 s …  1.763 s    20 runs

# with forwardable in neither
$ hyperfine -w 3 -r 20 "bundle exec rubocop"
Benchmark 1: bundle exec rubocop
  Time (mean ± σ):      1.656 s ±  0.020 s    [User: 1.817 s, System: 0.984 s]
  Range (min … max):    1.630 s …  1.700 s    20 runs
```
Copy link
Contributor

@marcandre marcandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and the benchmark ❤️

I am not opposed to not using the builtin forwardable but I believe we could keep the abstraction in place with a custom and minimal variant.

I commented on the rubocop thread.

marcandre added a commit that referenced this pull request Sep 1, 2024
marcandre added a commit that referenced this pull request Sep 1, 2024
marcandre added a commit that referenced this pull request Sep 1, 2024
@Earlopain Earlopain closed this Sep 2, 2024
marcandre added a commit that referenced this pull request Sep 3, 2024
@Earlopain Earlopain deleted the no-forwardable branch September 3, 2024 10:42
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Sep 3, 2024
Introduced in rubocop/rubocop-ast#312
Also see rubocop#13175

I performance tested this change and found no significant difference,
which makes sense since it's basically the same thing
bbatsov pushed a commit to rubocop/rubocop that referenced this pull request Sep 3, 2024
Introduced in rubocop/rubocop-ast#312
Also see #13175

I performance tested this change and found no significant difference,
which makes sense since it's basically the same thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants